<template>
  <el-card class="cardClass">
    <div slot="header" class="cardClass_header">
      <h3>牛场支出分析</h3>
      <div>
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-search"
          @click="searchHidden()"
          >搜索</el-button
        >
      </div>
    </div>
    <!-- 查询开始 -->
    <el-collapse-transition>
      <el-form
        :model="ruleForm"
        :inline="true"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        v-if="hidden"
      >
        <el-form-item label="业务日期：" prop="value" label-width="100px">
          <el-date-picker
            v-model="value1"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
            size="small"
            icon="el-icon-search"
            >查询</el-button
          >
          <el-button
            @click="resetForm('ruleForm')"
            size="small"
            icon="el-icon-refresh"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-collapse-transition>
    <!-- 查询结束 -->

    <!-- 表格开始 -->
    <el-table
      :data="tableData"
      empty-text="总计： 合计饲养头日： 0 合计使用总金额： 0"
      style="width: 100%; text-align: center; margin-top: 20px; padding: 10px"
    >
      <el-table-column label="犊牛" align="center">
        <el-table-column label="头日成本" align="center" >
          <el-table-column  align="center" prop="duniutourichengben"> </el-table-column
        ></el-table-column>
        <el-table-column label="总价" align="center">
          <el-table-column align="center" prop="duniuzongjia"> </el-table-column
        ></el-table-column>
      </el-table-column>
      <el-table-column label="育成牛" align="center">
        <el-table-column label="头日成本" align="center">
          <el-table-column  align="center" prop="yuchengniutourichengben"> </el-table-column
        ></el-table-column>
        <el-table-column label="总价" align="center">
          <el-table-column align="center" prop="yuchengniuzongjia">
          </el-table-column
        ></el-table-column>
      </el-table-column>
      <el-table-column label="青年牛" align="center">
        <el-table-column label="头日成本" align="center">
          <el-table-column prop="qingnianniutourichengben" align="center"> </el-table-column
        ></el-table-column>
        <el-table-column label="" align="center">
          <el-table-column prop="qingnianniuzongjia" align="center"> </el-table-column
        ></el-table-column>
      </el-table-column>
      <el-table-column label="泌乳牛" align="center">
        <el-table-column label="头日成本" align="center">
          <el-table-column prop="miruniutourichengbne" align="center"> </el-table-column
        ></el-table-column>
        <el-table-column label="总价" align="center">
          <el-table-column prop="miruniuzongjia" align="center"> </el-table-column
        ></el-table-column>
      </el-table-column>
      <el-table-column label="干奶牛" align="center">
        <el-table-column label="头日成本" align="center">
          <el-table-column prop="gannainiutourichengben" align="center"> </el-table-column
        ></el-table-column>
        <el-table-column label="头日成本" align="center">
          <el-table-column prop="gannainiuzongjia" align="center"> </el-table-column
        ></el-table-column>
      </el-table-column>
      <el-table-column label="操作" align="center" width="220">
        <template slot-scope="scope">
          <el-button
            type="warning"
            size="mini"
            icon="el-icon-edit"
            @click="open('修改支出分析', scope.row)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 表格结束 -->

    <!-- 分页开始 -->
    <el-pagination
      background
      layout="total, prev, pager, next, jumper"
      
      :total="total"
      :page-size="ruleForm.pageSize"
      v-show="!loading"
      :current-page="ruleForm.pageNum"
      @current-change="changePage"
      class="pageClass"
    ></el-pagination>
    <!-- 分页结束 -->

    <!-- 新增修改组件开始 -->
    <addcattlefarmexpenditure ref="addcattlefarmexpenditureRef"></addcattlefarmexpenditure>
    <!-- 新增修改组件结束 -->
  </el-card>
</template>

<script>
import addcattlefarmexpenditure from "@/components/employee/addcattlefarmexpenditure";
import { querycattlefarmexpenditure } from "@/apis/employee/cattlefarmexpenditure.js";

export default {
  components: {
    addcattlefarmexpenditure
  },
  data() {
    return {
      value1: "",
      total: null, // 分页
      loading: true, // 加载
      hidden: false, // 控制搜索表单显示状态
      // 表格开始
      tableData: [],
      // 表格结束
      ruleForm: {
        key: "duniuzongjia",
        value: "",
        flag: 0,
        pageNum: 1,
        pageSize: 10,
      },
      keyOptions: [
        { value: "duniuzongjia", label: "犊牛总价" },
        { value: "yuchengniuzongjia", label: "育成牛总价" },
        { value: "qingnianniuzongjia", label: "青年牛总价" },
      ],
      rules: {
        key: [{ required: true, message: "请选择查询字段", trigger: "blur" }],
      },
    };
  },
  created() {
    this.search();
  },
  methods: {
    // 搜索隐藏
    searchHidden() {
      this.hidden = !this.hidden;
    },
    // 新增/修改弹窗
    open(title, row) {
      this.$refs.addcattlefarmexpenditureRef.show(title, row);
    },
    // 搜索方法
    search() {
      const _this = this;
      _this.loading = true;
      querycattlefarmexpenditure(_this.ruleForm).then((res) => {
        console.log(res);
        _this.tableData = res.data;
        _this.total = res.total;
        _this.loading = false;
      });
    },
    // 搜索
    submitForm(formName) {
      const _this = this;
      _this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.ruleForm.pageNum = 1; // 查询重置页数
          _this.search(_this.ruleForm);
        }
      });
    },
    // 重置
    resetForm(formName) {
      let _this = this;
      this.$refs[formName].resetFields();
      this.search(_this.ruleForm);
      this.ruleForm.pageNum = 1; // 查询重置页数
    },
    // 分页
    changePage(pageNum) {
      this.ruleForm.pageNum = pageNum;
      this.search();
    },
  },
};
</script>

<style>
</style>